<?php

class FormsController extends FormController
{

  protected $table = 'auto_forms';

  protected $pk = 'form_id';

  protected function initialize()
  {
    parent::initialize();

    $this->Form->addElement(new FormElement_Text('form_title', 'Title'));
    $this->Form->addElement(new FormElement_Text('form_table', 'Table'));
    $this->Form->addElement(new FormElement_Text('form_pk', 'Primary Key'));

    $link = new FormElement_Link('form_id', 'Elements');
    $link->url = '/admin/form_builder/elements';

    $this->Form->addElement($link);
  }

  protected function createAction()
  {
    $form = array(
      'form_title' => 'New form'
    );

    $this->Form->gateway()->save($form);

    return $this->response->redirect(array($this->request->route(), array('action' => 'edit', $this->pk => $form[$this->pk])));
  }

}
